import request from "./config/request"
import { ApiResponse } from "./type"

export interface MenuData {
  id: number
  title: string
  path: string
  name: string
  icon: string
  parent_id: string
  sort_id: number
}

export const getAllMenus = (): Promise<ApiResponse<MenuData[]>> => {
  return request.get("/access/menu")
}

export const addMenu = (data: MenuData): Promise<ApiResponse<MenuData>> => {
  return request.post("/access/menu", data)
}

export const removeMenuById = (id: number): Promise<ApiResponse<null>> => {
  return request.delete(`/access/menu/${id}`)
}

export const updateMenuById = (
  id: number,
  data: Partial<MenuData>
): Promise<ApiResponse<null>> => {
  return request.put(`/access/menu/${id}`, data)
}

export const updateBulkMenu = (
  data: MenuData[]
): Promise<ApiResponse<null>> => {
  return request.patch("/access/menu/update", {
    access: data
  })
}
